import React, { useState, useEffect, useCallback, useRef } from 'react';
//倒计时
import '../sass/Time.scss'
const Time = () => {
    const intervalRef = useRef<any>(null);
    const [count, changeCount] = useState(59);
    useEffect(() => {
        return () => {
            clearInterval(intervalRef.current);
        };
    }, []);
    useEffect(() => {
        if (count === 59) {
            intervalRef.current = setInterval(() => {
                changeCount((preCount) => preCount - 1);
            }, 1000);
        } else if (count === 0) {
            clearInterval(intervalRef.current);
        }
    }, [count]);

    return (
        <div id='shijian'>
            {count}
        </div>
    );
};

export default Time;